using System;
using System.ComponentModel;
using System.Transactions;

using SIS.ENT;
using SIS.DAL;


namespace SIS.BLL {

/// <summary>
/// The ReligionCodeTableManager class is responsible for managing BO.ReligionCodeTable objects in the system.
/// </summary>
[DataObjectAttribute()]
public class ReligionCodeTableManager
  {

#region "Public Methods"

/// <summary>
/// Gets a list with all ReligionCodeTable objects in the database.
/// </summary>
/// <returns>A list with all ReligionCodeTable from the database when the database contains any, or null otherwise.</returns>
[DataObjectMethod(DataObjectMethodType.Select, true)]
public static ReligionCodeTableList GetList(){
return ReligionCodeTableDB.GetList();
}

/// <summary>
/// Gets a single ReligionCodeTable from the database without its data.
/// </summary>
/// <param name="religionCode">The ReligionCode of the ReligionCodeTable in the database.</param>
/// <returns>A ReligionCodeTable object when the ReligionCode exists in the database, or <see langword="null"/> otherwise.</returns>
[DataObjectMethod(DataObjectMethodType.Select, false)]
public static ReligionCodeTable GetItem(short religionCode,int SchoolKey){
return GetItem(religionCode, SchoolKey,false);
}

/// <summary>
/// Gets a single ReligionCodeTable from the database.
/// </summary>
/// <param name="religionCode">The ReligionCode of the ReligionCodeTable in the database.</param>
/// <param name="getReligionCodeTableRecords">Determines whether to load all associated ReligionCodeTable records as well.</param>
/// <returns>
/// A ReligionCodeTable object when the ReligionCode exists in the database, or <see langword="null"/> otherwise.
/// </returns>
[DataObjectMethod(DataObjectMethodType.Select, false)]
public static ReligionCodeTable GetItem(short religionCode,int SchoolKey, bool getReligionCodeTableRecords){
ReligionCodeTable myReligionCodeTable = ReligionCodeTableDB.GetItem(religionCode);
if (myReligionCodeTable != null && getReligionCodeTableRecords){
myReligionCodeTable.familyMemberProfileTables = FamilyMemberProfileTableDB.GetListByReligionCode(religionCode);
}
if (myReligionCodeTable != null && getReligionCodeTableRecords){
myReligionCodeTable.guardianProfileTables = GuardianProfileTableDB.GetListByReligionCode(religionCode);
}
if (myReligionCodeTable != null && getReligionCodeTableRecords){
myReligionCodeTable.studentProfileTables = StudentProfileTableDB.GetListByReligionCode(religionCode);
}
if (myReligionCodeTable != null && getReligionCodeTableRecords){
myReligionCodeTable.teacherProfileTables = TeacherProfileTableDB.GetListByReligionCode(religionCode,SchoolKey);
}
if (myReligionCodeTable != null && getReligionCodeTableRecords){
myReligionCodeTable.userProfileTables = UserProfileTableDB.GetListByReligionCode(religionCode);
}
return myReligionCodeTable;
}

/// <summary>
/// Saves a ReligionCodeTable in the database.
/// </summary>
/// <param name="myReligionCodeTable">The ReligionCodeTable instance to save.</param>
/// <returns>The new ReligionCode if the ReligionCodeTable is new in the database or the existing ReligionCode when an item was updated.</returns>
[DataObjectMethod(DataObjectMethodType.Update, true)]
public static short Save(ReligionCodeTable myReligionCodeTable){
using (TransactionScope myTransactionScope = new TransactionScope()){
short religionCodeTableReligionCode = ReligionCodeTableDB.Save(myReligionCodeTable);
foreach (FamilyMemberProfileTable myFamilyMemberProfileTable in myReligionCodeTable.familyMemberProfileTables){
myFamilyMemberProfileTable.ReligionCode = religionCodeTableReligionCode;
FamilyMemberProfileTableDB.Save(myFamilyMemberProfileTable);
}
foreach (GuardianProfileTable myGuardianProfileTable in myReligionCodeTable.guardianProfileTables){
myGuardianProfileTable.ReligionCode = religionCodeTableReligionCode;
GuardianProfileTableDB.Save(myGuardianProfileTable);
}
foreach (StudentProfileTable myStudentProfileTable in myReligionCodeTable.studentProfileTables){
myStudentProfileTable.ReligionCode = religionCodeTableReligionCode;
StudentProfileTableDB.Save(myStudentProfileTable);
}
foreach (TeacherProfileTable myTeacherProfileTable in myReligionCodeTable.teacherProfileTables){
myTeacherProfileTable.ReligionCode = religionCodeTableReligionCode;
TeacherProfileTableDB.Save(myTeacherProfileTable);
}
foreach (UserProfileTable myUserProfileTable in myReligionCodeTable.userProfileTables){
myUserProfileTable.ReligionCode = religionCodeTableReligionCode;
UserProfileTableDB.Save(myUserProfileTable);
}

//  Assign the ReligionCodeTable its new (or existing ReligionCode).
myReligionCodeTable.ReligionCode = religionCodeTableReligionCode;

myTransactionScope.Complete();

return religionCodeTableReligionCode;
}
}

/// <summary>
/// Deletes a ReligionCodeTable from the database.
/// </summary>
/// <param name="myReligionCodeTable">The ReligionCodeTable instance to delete.</param>
/// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
[DataObjectMethod(DataObjectMethodType.Delete, true)]
public static bool Delete(ReligionCodeTable myReligionCodeTable){
return ReligionCodeTableDB.Delete(myReligionCodeTable.ReligionCode);
}

#endregion

}

}
